package online.afeibaili.storebackendframework.controller;

import online.afeibaili.storebackendframework.model.Coupon;
import online.afeibaili.storebackendframework.server.CouponServer;
import online.afeibaili.storebackendframework.server.GetCouponServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
//private double discount; // 优惠折扣
//private double reprice; // 优惠价格
//        if (reprice == 0 ^ discount == 0) {
//            isTrue =  couponMapper.insert(coupon);
//        }
//private double min; // 优惠最低价格
//private int quantity; // 优惠卷数量
//private long expireTime; // 到期时间
@RestController
@RequestMapping("/admin/coupon")
public class CouponAdminController  {
    @Autowired
    private CouponServer couponServer;
    
    @Autowired
    private GetCouponServer getCouponServer;
    
    @PostMapping("/insert")
    public ResponseEntity<Map<String, Object>> insert(@RequestBody Coupon coupon) {
        return ResponseEntity.ok(Map.of("code", 200, "result", couponServer.insert(coupon)));
    }
    
    @GetMapping("/listAll")
    public ResponseEntity<Map<String, Object>> listAll() {
        return ResponseEntity.ok(Map.of("code", 200, "result", couponServer.selectAll()));
    }
    
    @GetMapping("/giveCoupon")
    public ResponseEntity<Map<String, Object>> giveCoupon(@RequestParam String userId, @RequestParam long couponId) {
        return ResponseEntity.ok(Map.of("code", 200, "message", getCouponServer.getCoupon(userId, couponId)));
    }
    @GetMapping("/getCount")
    public ResponseEntity<Map<String, Object>> getCount() {
        return ResponseEntity.ok(Map.of("code", 200, "result", couponServer.getCount()));
    }
}